package com.cn.kehong.controller;


import com.cn.kehong.api.IProductPackageFenjiService;
import com.cn.kehong.domain.ProductPackageFenji;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/pfenji")
public class ProductPackageFenjiController {

    @Autowired
    private IProductPackageFenjiService productPackageFenjiService;

    @RequestMapping("/getProductPackageFenjiByPackageId/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductPackageFenji>> getProductPackageFenjiByPackageId(@PathVariable(value = "frontToken", required = true) String frontToken, String packageId) throws Exception {
        JsonResponse<List<ProductPackageFenji>> response = new JsonResponse<>();
        List<ProductPackageFenji> productPackageFenjis = productPackageFenjiService.getProductPackageFenjiByPackageId(packageId);
        response.setResult(productPackageFenjis);
        response.setSuccess(true);
        return response;
    }


    @RequestMapping("/addBatchProductPackageFenji/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addBatchProductPackageFenji(@RequestBody List<ProductPackageFenji> productPackageFenjis, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productPackageFenjiService.addBatchProductPackageFenji(productPackageFenjis);
        return CommonUtil.getResponseData(response,result);
    }

}
